﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;

namespace RCMC
{
	internal class WakeOnLan
	{
		public static void Send(string mac)
		{
			//string mac = "00-1F-D0-8C-9E-E5";
			string[] macParts = mac.Split('-', ':');
			byte[] macBytes = new byte[] 
			{ 
				Convert.ToByte(macParts[0], 16),
				Convert.ToByte(macParts[1], 16),
				Convert.ToByte(macParts[2], 16),
				Convert.ToByte(macParts[3], 16),
				Convert.ToByte(macParts[4], 16),
				Convert.ToByte(macParts[5], 16)
			};

			byte[] packetData = new byte[17 * 6];
			int c = 0;

			for (int i = 0; i < 6; i++)
				packetData[c++] = 255;

			for (int i = 0; i < 16; i++)
				for (int x = 0; x < 6; x++)
					packetData[c++] = macBytes[x];

			IPEndPoint endPoint = new IPEndPoint(IPAddress.Broadcast, 7);
			UdpClient client = new UdpClient();

			client.Send(packetData, packetData.Length, endPoint);
		}
	}
}
